package com.customer.Test;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import spring.cloud.pojo.Depart;

import java.util.List;

/**
 * @author cyt
 * @create 2020-03-11 21:50
 */
@RestController
public class Controller {

    // 消费者 不需要service层

    // ribbon 的地址应该是一个变量， 我们应该通过服务名来访问

    private static final String Net_Add = "http://APPLICATION-PROVIDER//";
    // 原始的resttemp

    // private static final String Net_Add = "http://localhost:8001//";
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/hystrix/{id}")
    public Depart hystrix(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(Net_Add + "hystrix//" + id, Depart.class);
    }


    @RequestMapping("/get")
    public List<Depart> getAll() {
        System.out.println(Net_Add + "getAll");
        return restTemplate.getForObject(Net_Add + "getAll", List.class);
    }

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }
}
